import os
from PIL import Image
from tqdm import tqdm

path = 'D:\guomengqi\学习资料\数据集\practice_garden/'  # 待转换格式的图片所在文件夹
path1 = 'D:\guomengqi\学习资料\数据集\practice_garden1/'  # 转换后的图片存储路径

files = os.listdir(path)
for n, filename in tqdm(enumerate(files), total=len(files)):
    # print(filename)
    png = Image.open(path + filename)
    file_string = os.path.splitext(filename)[0]
    temp = file_string.split('.')  # 在 ‘.’ 处分割字符串
    png.save(path1 + temp[0] + ".jpg")  # 转换jpg格式就写 “.jpg”